/*
 * Copyright 2025 Redpanda Data, Inc.
 *
 * Licensed as a Redpanda Enterprise file under the Redpanda Community
 * License (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * https://github.com/redpanda-data/redpanda/blob/master/licenses/rcl.md
 */

#pragma once

#include "cloud_topics/level_one/compaction/meta.h"
#include "ssx/semaphore.h"

namespace cloud_topics::l1 {

// The policy controlling the frequency by which updates generated by compaction
// related work should be committed to the metastore and uploaded to cloud
// storage by a `compaction_committer`.
class committing_policy {
public:
    // Enum describing the `committing_policy`'s response to a newly arrived
    // update (see `on_update()`).
    enum class update_response { preempt, wait };

    committing_policy() = default;
    committing_policy(const committing_policy&) = delete;
    committing_policy& operator=(const committing_policy&) = delete;
    committing_policy(committing_policy&& other) noexcept = default;
    committing_policy& operator=(committing_policy&&) noexcept = default;
    virtual ~committing_policy() = default;

    // Invoked when the `compaction_committer` recieves an update.
    // Returns an `update_response` intended to let the caller know whether the
    // policy deems the accumulated updates immediately ready for committing
    // (`preempt`) or to continue waiting (`wait`).
    virtual update_response on_update(const object_output_t&) = 0;

    // Invoked when the `compaction_committer` is ready to potentially commit
    // some updates as part of its regularly scheduled polling.
    virtual bool should_commit() const = 0;
};

// Policy to commit updates as soon as they arrive (alerts on every update). No
// batching implemented.
class commit_on_update_policy : public committing_policy {
public:
    update_response on_update(const object_output_t&) final;

    bool should_commit() const final;
};

std::unique_ptr<committing_policy> make_default_committing_policy();

} // namespace cloud_topics::l1
